//Mark O'Meara
//08332240
//CS2011
//Due: 18/01/2010

import javax.swing.JOptionPane;

public class SSAapp {
	public static void main(String[] args) {
		
		ListMaker listmaker = new ListMaker();
		String profile;
		String circumstance;
		Product[] productlist;
		
		do{
			//Get profile
			profile = JOptionPane.showInputDialog("Please select one of the following profiles:\n\n" +
					" Single\n Family\n Retired\n\n");
			//Get Circumstances
			circumstance = JOptionPane.showInputDialog("Please select one of the following circumstances:\n\n" + 
					" Weekday\n Weekend\n Summer\n Winter\n ");
		}while(listmaker.checkInput(profile,circumstance) == false); //Check input
		
		//Get products
		productlist = listmaker.getProducts(profile,circumstance);
		
		String printproducts = "";
		//Loop, adding products to single string
		for(int i = 0; i<= 4;i++){
	      
			try {
				//Adds product to string, separates products by new line
				printproducts = printproducts + "\n" + (i + 1) + ". " + productlist[i].getName();
			}
			//Exception if array of products returned is smaller than 4 (0 - 4)
			catch (ArrayIndexOutOfBoundsException e ) {
				System.out.println("Product " + (i+1) + " Missing");
			}
			//Exception if product is missing from array returned
			catch (NullPointerException e ) {
				System.out.println("Product " + (i+1) + " Missing");
			}
		}
		
		//Print Shopping List
		JOptionPane.showMessageDialog(null,printproducts,"Your Shopping List",JOptionPane.INFORMATION_MESSAGE);
	}
}
